package me.ak.file;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;

import me.ak.StatRepo;
import me.ak.utils.CManip;

import org.jnbt.CompoundTag;
import org.jnbt.NBTOutputStream;
import org.jnbt.StringTag;

public class NBTFileFormat {

	public void save(File location, Saveable root) {
		CompoundTag score = root.saveNBT();
		StringTag version = new StringTag("CreatedWithVersion", StatRepo.VERSION_STRING);
		CompoundTag full = new CompoundTag("UberScoreFile", CManip.toMap(version, score));

		try {
			if (!location.exists())
				location.createNewFile();
			NBTOutputStream out = new NBTOutputStream(new FileOutputStream(location));
			out.writeTag(full);
			out.close();
		} catch (FileNotFoundException e) {
		} catch (IOException e) {
			// TODO: WARN USER
		}
	}

}
